package com.fanxuankai.boot.confluent.config;

import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.TemplateUtil;
import io.confluent.ksql.api.client.Client;
import io.confluent.ksql.api.client.ClientOptions;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author fanxuankai
 */
@Configuration
@EnableConfigurationProperties({KsqldbProperties.class})
public class AppAutoConfiguration {
    @Bean
    public Client client(KsqldbProperties properties) {
        ClientOptions options = ClientOptions.create().setHost(properties.getHost()).setPort(properties.getPort());
        return Client.create(options);
    }

    @Bean
    public TemplateEngine templateEngine() {
        return TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
    }

}
